/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * View.java
 *
 * Created on 14/05/2012, 20:52:54
 */
package br.com.tamagochi.view;

import br.com.tamagochi.logica.Facade;
import java.awt.Color;
import java.awt.Image;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * Esta Classe representa a interface com o usuario do bicho vitual,
 * onde você poderá visualizar os estados, os niveis destes estados e
 * a parte de interação com o bicho virtual.
 * 
 * @author Allan & Fabiana
 */
public class View extends javax.swing.JFrame implements ViewObserve{

    private Facade facade;
    private String TYPE_FILE = "properties"; 
    
    /** Creates new form View */
    public View() {
        initComponents();
        
        
        
        this.facade = new Facade();
        
        this.setLocationRelativeTo(null);
        
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabelFome = new javax.swing.JLabel();
        jProgressBarFome = new javax.swing.JProgressBar();
        jProgressBarSono = new javax.swing.JProgressBar();
        jLabelSono = new javax.swing.JLabel();
        jLabelFelicidade = new javax.swing.JLabel();
        jProgressBarFelicidade = new javax.swing.JProgressBar();
        jProgressBarSaude = new javax.swing.JProgressBar();
        jTextFieldIdade = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabelSaude = new javax.swing.JLabel();
        jProgressPeso = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        gifPanel1 = new br.com.tamagochi.view.GifPanel();
        jPanel3 = new javax.swing.JPanel();
        jButtonComer = new javax.swing.JButton();
        jComboBoxComer = new javax.swing.JComboBox();
        jComboBoxDormir = new javax.swing.JComboBox();
        jButtonDormir = new javax.swing.JButton();
        jButtonBrincar = new javax.swing.JButton();
        jComboBoxBrincar = new javax.swing.JComboBox();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItemNovoJogo = new javax.swing.JMenuItem();
        jMenuItemSalvar = new javax.swing.JMenuItem();
        jMenuItemCarregar = new javax.swing.JMenuItem();
        jMenuItemSair = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("JTamagochi");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Niveis"));

        jLabelFome.setText("Fome:");

        jProgressBarFome.setFont(new java.awt.Font("Tahoma", 1, 11));
        jProgressBarFome.setForeground(new java.awt.Color(0, 0, 255));
        jProgressBarFome.setStringPainted(true);

        jProgressBarSono.setFont(new java.awt.Font("Tahoma", 1, 11));
        jProgressBarSono.setForeground(new java.awt.Color(0, 0, 255));
        jProgressBarSono.setStringPainted(true);

        jLabelSono.setText("Sono:");

        jLabelFelicidade.setText("Felicidade:");

        jProgressBarFelicidade.setFont(new java.awt.Font("Tahoma", 1, 11));
        jProgressBarFelicidade.setForeground(new java.awt.Color(0, 0, 255));
        jProgressBarFelicidade.setStringPainted(true);

        jProgressBarSaude.setFont(new java.awt.Font("Tahoma", 1, 11));
        jProgressBarSaude.setForeground(new java.awt.Color(0, 0, 255));
        jProgressBarSaude.setStringPainted(true);

        jTextFieldIdade.setEditable(false);
        jTextFieldIdade.setFont(new java.awt.Font("Tahoma", 1, 11));
        jTextFieldIdade.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        jLabel2.setText("Idade:");

        jLabelSaude.setText("Saude:");

        jProgressPeso.setFont(new java.awt.Font("Tahoma", 1, 11));
        jProgressPeso.setString("");
        jProgressPeso.setStringPainted(true);

        jLabel1.setText("Peso:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jSeparator2)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelFome)
                            .addComponent(jLabelFelicidade)
                            .addComponent(jLabelSono)
                            .addComponent(jLabelSaude)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jProgressBarFome, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jProgressBarSono, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jProgressBarFelicidade, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jProgressBarSaude, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jProgressPeso, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldIdade, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelFome)
                    .addComponent(jProgressBarFome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelSono)
                    .addComponent(jProgressBarSono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jProgressBarFelicidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelFelicidade))
                .addGap(8, 8, 8)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jProgressBarSaude, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelSaude))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jProgressPeso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldIdade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(163, 163, 163))
        );

        gifPanel1.setPreferredSize(new java.awt.Dimension(405, 405));
        gifPanel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gifPanel1MouseClicked(evt);
            }
        });

        javax.swing.GroupLayout gifPanel1Layout = new javax.swing.GroupLayout(gifPanel1);
        gifPanel1.setLayout(gifPanel1Layout);
        gifPanel1Layout.setHorizontalGroup(
            gifPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        gifPanel1Layout.setVerticalGroup(
            gifPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Ações"));

        jButtonComer.setText("Comer");
        jButtonComer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonComerActionPerformed(evt);
            }
        });

        jComboBoxComer.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jComboBoxDormir.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jButtonDormir.setText("Dormir");
        jButtonDormir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDormirActionPerformed(evt);
            }
        });

        jButtonBrincar.setText("Brincar");
        jButtonBrincar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBrincarActionPerformed(evt);
            }
        });

        jComboBoxBrincar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButtonComer)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxComer, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(13, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButtonDormir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxDormir, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(13, 13, 13))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jButtonBrincar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBoxBrincar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonComer)
                    .addComponent(jComboBoxComer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonDormir)
                    .addComponent(jComboBoxDormir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonBrincar)
                    .addComponent(jComboBoxBrincar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(gifPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(gifPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenu1.setText("Arquivo");

        jMenuItemNovoJogo.setText("Novo Jogo");
        jMenuItemNovoJogo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemNovoJogoActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemNovoJogo);

        jMenuItemSalvar.setText("Salvar Jogo");
        jMenuItemSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSalvarActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemSalvar);

        jMenuItemCarregar.setText("Carregar Jogo");
        jMenuItemCarregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemCarregarActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemCarregar);

        jMenuItemSair.setText("Sair");
        jMenuItemSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItemSairActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItemSair);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItemNovoJogoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNovoJogoActionPerformed
        if(this.facade.estaJogando()){
            int option = JOptionPane.showConfirmDialog(null, "Deseja salvaro estado do JTamagochi", "Atenção", JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);

            switch(option){
                case JOptionPane.YES_OPTION:{
                    salvar();
                    this.facade.novoJogo(this);
                    break;
                }
                case JOptionPane.NO_OPTION: {
                    this.facade.novoJogo(this);
                    break;
                }
            }
        }else{
            this.facade.novoJogo(this);
        }
        
    }//GEN-LAST:event_jMenuItemNovoJogoActionPerformed

    private void jButtonDormirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDormirActionPerformed
        this.facade.dormir(jComboBoxDormir.getSelectedIndex());
    }//GEN-LAST:event_jButtonDormirActionPerformed

    private void jButtonComerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonComerActionPerformed
        this.facade.comer(jComboBoxComer.getSelectedIndex());
    }//GEN-LAST:event_jButtonComerActionPerformed
    
    private void gifPanel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gifPanel1MouseClicked
        int centerWidth = this.gifPanel1.getWidth() / 2;
        if(evt.getX() < centerWidth){
           this.facade.brincarLeft();
        }else{
           this.facade.brincarRight();
        }
        
    }//GEN-LAST:event_gifPanel1MouseClicked

    private void jButtonBrincarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBrincarActionPerformed
        this.facade.brincar(jComboBoxBrincar.getSelectedIndex());
    }//GEN-LAST:event_jButtonBrincarActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        verificar();
    }//GEN-LAST:event_formWindowClosing

    private void jMenuItemSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSairActionPerformed
        verificar();
    }//GEN-LAST:event_jMenuItemSairActionPerformed

    private void jMenuItemCarregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCarregarActionPerformed
        if(this.facade.estaJogando()){
            int option = JOptionPane.showConfirmDialog(null, "Deseja salvaro estado do JTamagochi", "Atenção", JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);

            switch(option){
                case JOptionPane.YES_OPTION:{
                    salvar();
                    carregar();
                    break;
                }
                case JOptionPane.NO_OPTION: {
                    carregar();
                    break;
                }
            }
        }else{
            carregar();
        }// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItemCarregarActionPerformed

    private void jMenuItemSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSalvarActionPerformed
        salvar();
    }//GEN-LAST:event_jMenuItemSalvarActionPerformed

    
    private void verificar(){
        if(this.facade.estaJogando()){
            int option = JOptionPane.showConfirmDialog(null, "Deseja salvaro estado do JTamagochi", "Atenção", JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);

            switch(option){
                case JOptionPane.YES_OPTION:{
                    salvar();
                    break;
                }
                case JOptionPane.NO_OPTION: {
                    System.exit(0);
                }
            }
        }else{
            System.exit(0);
        }
    }
    
    private void salvar() {
        if (this.facade.estaJogando()) {
            JFileChooser jfc = new JFileChooser("saves/");
            jfc.setFileFilter(new FileNameExtensionFilter(TYPE_FILE, TYPE_FILE));

            jfc.showDialog(null, "Salvar");

            if (jfc.getSelectedFile() != null) {

                String aboslutePath = jfc.getSelectedFile().getAbsolutePath();

                aboslutePath += "." + TYPE_FILE;

                this.facade.salvarJogo(aboslutePath);
            }
        }

    }
    
    private void carregar(){
        JFileChooser jfc = new JFileChooser("saves/");
        jfc.setFileFilter(new FileNameExtensionFilter(TYPE_FILE, TYPE_FILE));
            
        jfc.showDialog(null, "Carregar");
        
        if(jfc.getSelectedFile() != null){

            String aboslutePath = jfc.getSelectedFile().getAbsolutePath();

            this.facade.carregarJogo(aboslutePath, this);
        }
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private br.com.tamagochi.view.GifPanel gifPanel1;
    private javax.swing.JButton jButtonBrincar;
    private javax.swing.JButton jButtonComer;
    private javax.swing.JButton jButtonDormir;
    private javax.swing.JComboBox jComboBoxBrincar;
    private javax.swing.JComboBox jComboBoxComer;
    private javax.swing.JComboBox jComboBoxDormir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelFelicidade;
    private javax.swing.JLabel jLabelFome;
    private javax.swing.JLabel jLabelSaude;
    private javax.swing.JLabel jLabelSono;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItemCarregar;
    private javax.swing.JMenuItem jMenuItemNovoJogo;
    private javax.swing.JMenuItem jMenuItemSair;
    private javax.swing.JMenuItem jMenuItemSalvar;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JProgressBar jProgressBarFelicidade;
    private javax.swing.JProgressBar jProgressBarFome;
    private javax.swing.JProgressBar jProgressBarSaude;
    private javax.swing.JProgressBar jProgressBarSono;
    private javax.swing.JProgressBar jProgressPeso;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextFieldIdade;
    // End of variables declaration//GEN-END:variables

    @Override
    public void notifyValues(int saude, int idade, int peso, int sono, int felicidade, int fome) {
        this.jProgressBarSono.setValue(sono);
        this.jProgressBarFelicidade.setValue(felicidade);
        this.jProgressBarSaude.setValue(saude);
        this.jProgressBarFome.setValue(fome);
        this.jProgressPeso.setValue(peso);
        this.jTextFieldIdade.setText(String.valueOf(idade));
        
        //representação do peso em forme de string
        this.jProgressPeso.setString(peso + "Kg");
        
    }
    
    @Override
    public void notifyImage(Image image){
        this.gifPanel1.setImage(image);
    }

    @Override
    public void notifyArray(Integer[] arrayUnd) {
        this.jComboBoxDormir.setModel(new DefaultComboBoxModel<Integer>(arrayUnd));
        this.jComboBoxBrincar.setModel(new DefaultComboBoxModel<Integer>(arrayUnd));
        this.jComboBoxComer.setModel(new DefaultComboBoxModel<Integer>(arrayUnd));
    }

    @Override
    public void notifyMinMax(int min, int max) {
        
        this.jProgressBarFome.setForeground(Color.BLUE);
        if(this.jProgressBarFome.getValue() > max){
            this.jProgressBarFome.setForeground(Color.RED);
        }
        
        if(this.jProgressBarFome.getValue() < min){
            this.jProgressBarFome.setForeground(Color.GREEN);
        }
        
        this.jProgressBarSono.setForeground(Color.BLUE);
        if(this.jProgressBarSono.getValue() > max){
            this.jProgressBarSono.setForeground(Color.RED);
        }
        
        if(this.jProgressBarSono.getValue() < min){
            this.jProgressBarSono.setForeground(Color.GREEN);
        }
        
        this.jProgressBarFelicidade.setForeground(Color.BLUE);
        if(this.jProgressBarFelicidade.getValue() > max){
            this.jProgressBarFelicidade.setForeground(Color.GREEN);
        }
        
        if(this.jProgressBarFelicidade.getValue() < min){
            this.jProgressBarFelicidade.setForeground(Color.RED);
        }
        
        this.jProgressBarSaude.setForeground(Color.BLUE);
        if(this.jProgressBarSaude.getValue() > max){
            this.jProgressBarSaude.setForeground(Color.GREEN);
        }
        
        if(this.jProgressBarSaude.getValue() < min){
            this.jProgressBarSaude.setForeground(Color.RED);
        }
        
    }

    @Override
    public void notifyStateOfAction(boolean dormir, boolean brincar, boolean comer) {
        this.jButtonDormir.setEnabled(dormir);
        this.jButtonBrincar.setEnabled(brincar);
        this.jButtonComer.setEnabled(comer);
    }

}
